
const { log } = console
export { //确保其他实例没有成员冲突

}

const foo: object = function () {  //object 不仅是指对象 而是除了原型对象以外的其他类型
    //可以使用对象字面量的方式

}

const arr1: Array<number> = []
const arr2: number[] = []

function sum(...args: number[]) {
    //判断是不是每个成员都是数组
    args.reduce((prev, current) => prev + current, 0)
}

sum(1, 3, 4)


//

const tuple: [string, number] = ['2cs', 18]

const [name, age] = tuple

Object.entries({

})
const compareF = {

}
const enum Compare { //入侵到 编译为双向键值对象
    LESS_THAN,
    MORE_THAN,
    QUUALS
}

const post = {
    status: Compare.LESS_THAN
}

log(Object.entries({ "foo": "foo", "baz": 56 }));

function sum2(a: number, b: number, ...rest: number[]): number {
    return a + b
}

function stringfy(value: any) {
    return JSON.stringify(value)
}

let age1 = 18

let foo1;

const nums = [101, 3, 4]

const res = nums.find(i => i > 100)
const num1 = res as number

interface Post {
    title: string
    content: string
    subTitle?: string //可选成员
    readonly summary: string //只读成员
}
const helloHi: Post = {
    title: "hello",
    content: "hi",
    summary: "23434"
}

interface cache {
    [prop: string]: string,
}
const Cache: cache = {

}
Cache.token = "value"


// 可选成员

class Person {
    public name: string //类的修饰符
    private age: number //类的修饰符
    protected readonly gender: boolean //只允许在子类访问成员
    constructor(name: string, age: number) {  //明确声明中拥有的一切属性，而不是在构造函数中动态添加
        this.name = name //必须声明
        this.age = age
        this.gender = true //初始化之后不能修改
    }
    sayHi() {
        log(`hi ${this.name}`)
    }


}

interface Eat {
    eat(food: string): void
}
interface Run {
    run(distance: string): void
}

class Students extends Person implements Eat, Run {
    private constructor(name: string, age: number) { //在外部， 不能实例化  
        super(name, age)
        console.log(this.gender)
    }
    run(distance: string): void {
        log(`直立跑${distance}`)
    }
    eat(food: string): void {
        log(`优雅的吃${food}`)
    }
    static create() {
        return new Students("Ella", 89)
    }
}



const person = new Person("Jack", 18)
const students = Students.create()


abstract class Animal {
    eat(food: string): void {
        log(`优雅的吃${food}`)
    }

    abstract run(distance: number): void
}

class Dog extends Animal {
    run(distance: number): void {
        log(`四脚爬行${distance}`)
    }
}

const dog = new Dog()
dog.eat('niha')

function createArray<T>(length: number, value:T):T[]{
     const arr = Array<T>(length).fill(value)
     return arr
}



